package 相向双指针

func minimumRefill(plants []int, capacityA int, capacityB int) int {
	//逻辑错误 要先判断水量
	left, right, cnt := 0, len(plants)-1, 0
	c1, c2 := capacityA, capacityB
	for left <= right {
		if capacityA < plants[left] {
			cnt++
			capacityA = c1
		}
		capacityA -= plants[left]
		left++
		if capacityB < plants[right] {
			cnt++
			capacityB = c2
		}
		capacityB -= plants[right]
		right--
		if left == right {
			if capacityA >= capacityB {
				if capacityA < plants[left] {
					cnt++
				}
				left++
			} else {
				if capacityB < plants[right] {
					cnt++
				}
				right--
			}
		}
	}
	return cnt
}
